//
//  AccountSafeMenuTableController.m
//  TenMinDemo
//
//  Created by Shawn Li on 2021/3/9.
//  Copyright © 2021 CYXiang. All rights reserved.
//

#import "AccountSafeMenuTableController.h"
#import "AssetPasswordController.h"
#import "ChangePswViewController.h"
#import "BindInfoViewController.h"
#import "SimpleInfoTabCell.h"

@interface AccountSafeMenuTableController ()
/// <#注释#>
@property (nonatomic, strong) NSArray *safeMenuList;
@end

@implementation AccountSafeMenuTableController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configMenuInfo];
    
    [LCNotifiCenter addObserver:self selector:@selector(refreshView) name:@"UserInfoUpdated" object:nil];
}

- (void)setupUI{
    [super setupUI];
    self.title = LCLocalString(@"account_security");
    [self.tableView registerNib:[UINib nibWithNibName:@"SimpleInfoTabCell" bundle:nil] forCellReuseIdentifier:@"SimpleInfoTabCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

- (void)refreshView{
    [self configMenuInfo];
    [self.tableView reloadData];
}

- (void)configMenuInfo{
    UserInfoModel *user = kAppDelegate.curUser;
    if (!user) {
        self.safeMenuList = @[];
        return;
    }
    NSArray *safeMenuList = @[
        @{@"title":@"HID",@"subTitle":user.hid,@"isHideArr":@(YES)},
        @{@"title":LCLocalString(@"phone_num"),@"subTitle":user.phone,@"isHideArr":@(NO)},
//        @{@"title":@"邮箱",@"subTitle":@"1999999@qq.com",@"isHideArr":@(NO)},
        @{@"title":LCLocalString(@"psw_xgmm"),@"subTitle":@"",@"isHideArr":@(NO)},
        @{@"title":LCLocalString(@"psw_zjmm"),@"subTitle":@"",@"isHideArr":@(NO)}
    ];
    
    self.safeMenuList = safeMenuList;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (!self.safeMenuList.count) {
        return 0;
    }
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return self.safeMenuList.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *safeMenuM = self.safeMenuList[indexPath.row];
    SimpleInfoTabCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleInfoTabCell"];
    NSString *title = safeMenuM[@"title"];
    cell.title.text = title;
    cell.subTitle.text = safeMenuM[@"subTitle"];
    BOOL isHID = [title isEqualToString:@"HID"];
    cell.subTitle.textColor = isHID?TextColor_929acc:[UIColor whiteColor];
    cell.moreArr.hidden = isHID;
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return  cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
            return;
            break;
        case 1:
        {
            BindInfoViewController *vc = LoadVCFormXib(BindInfoViewController);
            vc.bindInfoType = 0;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
//        case 2:
//        {
//            BindInfoViewController *vc = LoadVCFormXib(BindInfoViewController);
//            vc.bindInfoType = 1;
//            [self.navigationController pushViewController:vc animated:YES];
//
//        }
            break;
        case 2:
        {
            ChangePswViewController *vc = LoadVCFormXib(ChangePswViewController);
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 3:
        {
            AssetPasswordController *vc = LoadVCFormXib(AssetPasswordController);
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        default:
            break;
    }
}


@end
